﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using CNotebook;
using CNotebook.Inventory;

namespace NotebookS2
{
    public partial class BRW_QUARANTINED : RibbonForm
    {
        public BRW_QUARANTINED()
        {
            InitializeComponent();
        }

        public enum eSearch
        {
            BySupplier = 1,
            ByDocument = 2,
            ByItemCode = 3
        }

        public eSearch SearchOption { get; set; }
        public string ConnectionString { get; set; }
        public string ActiveUserID { get; set; }

        public string Reference { get; set; }
        public string CardCode { get; set; }
        public string CardName { get; set; }
        public string ItemCode { get; set; }
        public string ItemName { get; set; }
        public string Qty { get; set; }
        public string UoM { get; set; }

        void BindQuarantineItems()
        {
            StockManager oManager = new StockManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            gridControl1.DataSource = oManager.GetQuarantinedItems();
            gridControl1.Refresh();

            oManager.Close();
            
        }

        private void FND_QUARANTINED_ITEM_Load(object sender, EventArgs e)
        {
            BindQuarantineItems();
        }

       
        private void btnChoose_Click(object sender, EventArgs e) 
        {
            int iFocusRowHandled = gridView1.FocusedRowHandle;

            string _DocNum = gridView1.GetRowCellValue(iFocusRowHandled, gridView1.Columns["DocNum"]).ToString();
            string _CardCode = gridView1.GetRowCellValue(iFocusRowHandled, gridView1.Columns["CardCode"]).ToString();
            string _CardName = gridView1.GetRowCellValue(iFocusRowHandled, gridView1.Columns["CardName"]).ToString();
            string _ItemCode = gridView1.GetRowCellValue(iFocusRowHandled, gridView1.Columns["ItemCode"]).ToString();
            string _ItemName = gridView1.GetRowCellValue(iFocusRowHandled, gridView1.Columns["ItemName"]).ToString();
            string _Qty = gridView1.GetRowCellValue(iFocusRowHandled, gridView1.Columns["Qty"]).ToString();
            string _UoM = gridView1.GetRowCellValue(iFocusRowHandled, gridView1.Columns["UoM"]).ToString();


            this.Reference = _DocNum;
            this.CardCode = _CardCode;
            this.CardName = _CardCode;
            this.ItemCode = _ItemCode;
            this.ItemName = _ItemName;
            this.Qty = _Qty;
            this.UoM = _UoM;


            this.Close();
            

        }

        
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtDocNum_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            //txtReference.Text = this.Reference;
            //txtLocationCode.Text = this.WarehouseCode;
            //txtLocationName.Text = this.WarehouseName;
            //txtCardCode.Text = this.VendorCode;
            //txtCardName.Text = this.VendorName;
            //txtItemCode.Text = this.ItemCode;
            //txtItemName.Text = this.ItemName;
            //txtUoM.Text = this.UoM;
            //txtQty.Text = this.Quantity;
            //txtLotNumber.Text = this.LotNumber;

            int iFocusHandle = gridView1.FocusedRowHandle;
            QADocument oForm = new QADocument();

            oForm.ActiveUserID = this.ActiveUserID;
            oForm.ConnectionString = this.ConnectionString;

            oForm.Reference = gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["DocNum"]).ToString();
            oForm.WarehouseCode = gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["Location"]).ToString();
            oForm.WarehouseName = gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["LocationName"]).ToString();
            oForm.VendorCode = gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["CardCode"]).ToString();
            oForm.VendorName = gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["CardName"]).ToString();
            oForm.ItemCode = gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["ItemCode"]).ToString();
            oForm.ItemName = gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["ItemName"]).ToString();
            oForm.Quantity = gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["Qty"]).ToString();
            oForm.UoM = gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["UoM"]).ToString();
            oForm.LotNumber = gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["LotNumber"]).ToString();

            if (gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["ExpiryDate"]) != DBNull.Value)
            {
                oForm.ExpiryDate = Convert.ToDateTime(gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["ExpiryDate"]));
            }

            if (gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["MfrDate"]) != DBNull.Value)
            {
                oForm.ManufacturingDate = Convert.ToDateTime(gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["MfrDate"]));
            }
            
            oForm.UnitPrice = gridView1.GetRowCellValue(iFocusHandle, gridView1.Columns["UnitPrice"]).ToString();
            oForm.MdiParent = this.MdiParent;
            oForm.Show();

        }

       
      
    }
}
